/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JPanelChercherODS.java
 *
 * Created on 23 mai 2010, 18:20:27
 */

package responsableDeStage;

import com.mysql.jdbc.Connection;
import java.awt.Color;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Labassi Amine
 */
public class JPanelChercherODS extends javax.swing.JPanel {

    EcranRespDeStage parent ;
    Connection cnt ;
    int operation ;
    /** Creates new form JPanelChercherODS */
    public JPanelChercherODS(EcranRespDeStage pParent, Connection pCnt, int pOperation) {
        initComponents();
        parent = pParent ;
        cnt = pCnt ;
        operation = pOperation ;
        this.setBackground(Color.LIGHT_GRAY);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanelFiltres = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextFieldID = new javax.swing.JTextField();
        jButtonID = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldSujet = new javax.swing.JTextField();
        jButtonSujet = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldDuree = new javax.swing.JTextField();
        jButtonDuree = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldLieu = new javax.swing.JTextField();
        jButtonLieu = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableODS = new javax.swing.JTable();
        jButtonChargerODS = new javax.swing.JButton();
        jButtonAnnuler = new javax.swing.JButton();

        jPanelFiltres.setBorder(javax.swing.BorderFactory.createTitledBorder("Filtres"));

        jLabel1.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel1.setText("ID");

        jButtonID.setText("Filtrer");
        jButtonID.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonIDActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel2.setText("Sujet");

        jButtonSujet.setText("Filtrer");
        jButtonSujet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSujetActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel3.setText("Durée");

        jButtonDuree.setText("Filtrer");
        jButtonDuree.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDureeActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel4.setText("Lieu");

        jButtonLieu.setText("Filtrer");
        jButtonLieu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLieuActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelFiltresLayout = new javax.swing.GroupLayout(jPanelFiltres);
        jPanelFiltres.setLayout(jPanelFiltresLayout);
        jPanelFiltresLayout.setHorizontalGroup(
            jPanelFiltresLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelFiltresLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelFiltresLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldLieu, javax.swing.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE)
                    .addComponent(jTextFieldDuree, javax.swing.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE)
                    .addComponent(jTextFieldSujet, javax.swing.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE)
                    .addComponent(jTextFieldID, javax.swing.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE)
                    .addComponent(jLabel1)
                    .addComponent(jButtonID, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2)
                    .addComponent(jButtonSujet, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jButtonDuree, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButtonLieu, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        jPanelFiltresLayout.setVerticalGroup(
            jPanelFiltresLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelFiltresLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonID)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldSujet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonSujet)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldDuree, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonDuree)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldLieu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonLieu)
                .addContainerGap(71, Short.MAX_VALUE))
        );

        jTableODS.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "ID", "Sujet", "Durée", "Lieu", "Remunération"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.Integer.class, java.lang.String.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, true, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTableODS);

        jButtonChargerODS.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jButtonChargerODS.setText("Charger ODS");
        jButtonChargerODS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonChargerODSActionPerformed(evt);
            }
        });

        jButtonAnnuler.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jButtonAnnuler.setText("Annuler");
        jButtonAnnuler.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAnnulerActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelFiltres, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 660, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(624, Short.MAX_VALUE)
                .addComponent(jButtonAnnuler, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonChargerODS)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 415, Short.MAX_VALUE)
                    .addComponent(jPanelFiltres, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonChargerODS)
                    .addComponent(jButtonAnnuler))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonIDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonIDActionPerformed
       filtrerTableODS(1);
       parent.pack();
       parent.setVisible(true);
    }//GEN-LAST:event_jButtonIDActionPerformed

    private void jButtonSujetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSujetActionPerformed
        filtrerTableODS(2);
       parent.pack();
       parent.setVisible(true);
    }//GEN-LAST:event_jButtonSujetActionPerformed

    private void jButtonDureeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDureeActionPerformed
        filtrerTableODS(3);
       parent.pack();
       parent.setVisible(true);
    }//GEN-LAST:event_jButtonDureeActionPerformed

    private void jButtonLieuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLieuActionPerformed
       filtrerTableODS(4);
       parent.pack();
       parent.setVisible(true);
    }//GEN-LAST:event_jButtonLieuActionPerformed

    private void jButtonChargerODSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonChargerODSActionPerformed
        if (operation == 1 ) {
            JPanelModifyODS JPMODS = null ;
            try {
                JPMODS = new JPanelModifyODS(cnt, parent);
            } catch (SQLException ex) {
                Logger.getLogger(JPanelChercherODS.class.getName()).log(Level.SEVERE, null, ex);
            }
            parent.setContentPane(JPMODS);
            parent.pack();
            parent.setVisible(true);
        } else {
            JPanelSuppODS JPSODS = null ;
            try {
                JPSODS = new JPanelSuppODS(cnt, parent);
            } catch (SQLException ex) {
                Logger.getLogger(JPanelChercherODS.class.getName()).log(Level.SEVERE, null, ex);
            }
            parent.setContentPane(JPSODS);
            parent.pack();
            parent.setVisible(true);
        }

    }//GEN-LAST:event_jButtonChargerODSActionPerformed

    private void jButtonAnnulerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAnnulerActionPerformed
        jPanelVide JPVide = new jPanelVide() ;
        parent.setContentPane( JPVide);
        parent.pack();
        parent.setVisible(true);
    }//GEN-LAST:event_jButtonAnnulerActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAnnuler;
    private javax.swing.JButton jButtonChargerODS;
    private javax.swing.JButton jButtonDuree;
    private javax.swing.JButton jButtonID;
    private javax.swing.JButton jButtonLieu;
    private javax.swing.JButton jButtonSujet;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanelFiltres;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTableODS;
    private javax.swing.JTextField jTextFieldDuree;
    private javax.swing.JTextField jTextFieldID;
    private javax.swing.JTextField jTextFieldLieu;
    private javax.swing.JTextField jTextFieldSujet;
    // End of variables declaration//GEN-END:variables

    private void filtrerTableODS(int filtre){

        switch (filtre) {
            // ID
            case 1:
            //Sujet
            case 2:
            //Durée
            case 3:
            //Lieu
            case 4:

            //default
            default:
                break ;
        }
    }
}
